*. Table 5
use "temp/EIA_clean.dta", clear

bys year: egen totalmatfor = total(matfor) 
bys year: gen siAGG2 = totalmatfor / totalmat // aggregate imported input share
bys year: egen totalexports = total(exports)
bys year: gen xiAGG = totalexports / totalsales  // aggregate export share
bys year: egen shareMonly = mean(importer_only) // share of importers only 
bys year: egen shareXonly = mean(exporter_only) // share of exporters only 
bys year: egen shareMX = mean(MX)    // share of importer-exporters               
bys year: egen STDsi = sd(si)		 // standard deviation of import shares     
bys year: egen STDlnva = sd(log(mi)) // standard deviation of log material shares 
bys year: egen STDxi = sd(xi)    	 // standard deviation of export shares      
gen lva = log(mi)
bys year: egen CORRsixi = corr(si xi)    // correlation import shares export share 
bys year: egen CORRlnvasi = corr(lva si) // correlation log material shares import shares 
bys year: egen CORRlnvaxi = corr(lva xi) // correlation log material shares export shares 
bys year: egen Exports = total(exports)
bys year: gen ExportsUSD = Exports / er
label var ExportsUSD "USD Exports"
preserve
	collapse siAGG2 xiAGG shareMonly shareXonly shareMX STDlnva STDsi STDxi CORRlnvasi CORRlnvaxi CORRsixi ExportsUSD, by(year)
	gen shareM = shareMonly + shareMX // share of importers = share of importers-only + share of importer-exporters
	gen shareX = shareXonly + shareMX // share of exporters = share of exporters-only + share of importer-exporters
	drop shareMonly shareXonly
	label var siAGG2 "Aggregate import share"
	label var xiAGG "Aggregate export share"
	label var shareM "Fraction importers"
	label var shareX "Fraction exporters"
	label var shareMX "Fraction global"
	label var STDlnva "Dispersion in materials"
	label var STDsi "Dispersion in imp. shares"
	label var STDxi "Dispersion in exp. shares"
	label var CORRlnvasi "Corr. materials-imp. shares"
	label var CORRlnvaxi "Corr. materials-exp. shares"
	label var CORRsixi "Corr. imp.-exp. shares"	
	export excel siAGG2 xiAGG shareM shareX shareMX STDlnva STDsi STDxi CORRlnvasi CORRlnvaxi CORRsixi using "../../Output/Table5_Data" if year==1994, first(varl) sh("Table5") replace
	
	* Growth in exports between avg of 95-99 and 94
	keep if year>=1994 & year<=1999
	gen temp1 = 0
	replace temp1 = 1 if year==1994	
	foreach x of var ExportsUSD{
	gen `x'temp = `x' * temp1
	egen `x'94 = total(`x'temp)
	gen `x'_growth = (`x'/`x'94-1)*100
	drop `x'temp
	}	
	drop if year==1994
	collapse ExportsUSD_growth
	label var ExportsUSD_growth "Growth in total exports"
	export excel ExportsUSD_growth using "../../Output/Table5_Data", first(varl) sh("Last row")
restore
